﻿#include <iostream>
using namespace std;

class Abstraction {
public:
    virtual void Operation() = 0;

    virtual ~Abstraction(){}
protected:
    Abstraction(){}
};


class Implementor
{
public:
    Implementor() {}
    virtual ~Implementor() {}

    virtual void Operation() {}
};

class ConcreteImplementor:public Implementor
{
public:
    ConcreteImplementor(){}
    virtual ~ConcreteImplementor(){}

    void Operation()
    {
        cout << "ConcreteImplementor operation" << endl;
    }
};

class RefinedAbstraction : public Abstraction
{
public:
    RefinedAbstraction(Implementor* imp)
    {
        m_pImplementor = imp;
    }

    virtual ~RefinedAbstraction()
    {
        m_pImplementor = nullptr;
    }

    void Operation()
    {
        if (m_pImplementor != nullptr)
        {
			m_pImplementor->Operation();
        }
    }

private:
    Implementor* m_pImplementor;
};

int main()
{
    Implementor* imp = new ConcreteImplementor();
    RefinedAbstraction* ref = new RefinedAbstraction(imp);
    ref->Operation();

    delete imp;
    delete ref;
    return 0;
}
